{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- ##  简单实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Audi\n",
      "BMW\n",
      "Subaru\n",
      "Toyota\n"
     ]
    }
   ],
   "source": [
    "# 先写一个car列表\n",
    "cars = ['audi','bmw','subaru','toyota']\n",
    "\n",
    "for car in cars:\n",
    "    if car == 'bmw':\n",
    "        print(car.upper())\n",
    "    else:\n",
    "        print(car.title())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hold the anchovies!\n"
     ]
    }
   ],
   "source": [
    "# 检查是否不相等\n",
    "requested_topping = 'mushrooms'\n",
    "\n",
    "# 如果requested topping 不是anchoives\n",
    "if requested_topping != 'anchovies':\n",
    "    print(\"Hold the anchovies!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "That is not the correct answer. Please try again!\n"
     ]
    }
   ],
   "source": [
    "# 比较数字\n",
    "answer = 17\n",
    "\n",
    "if answer != 42:\n",
    "    print(\"That is not the correct answer. Please try again!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Marie,you can post a response if you wish.\n"
     ]
    }
   ],
   "source": [
    "# 检查特定值是否不包含在列表中\n",
    "banned_users = ['andrew','carolina','david']\n",
    "user = 'marie'\n",
    "\n",
    "# not in 判断是否在列表中\n",
    "if user not in banned_users:\n",
    "    print(user.title() + \",you can post a response if you wish.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sorry,you are too young to vote.\n",
      "Please register to vote as soon as you turn 18!\n"
     ]
    }
   ],
   "source": [
    "# if-else语句\n",
    "\n",
    "age = 17\n",
    "if age >= 18:\n",
    "    print(\"you are old enough to vote!\")\n",
    "    print(\"have you registered to vote yet?\")\n",
    "\n",
    "else:\n",
    "    print(\"Sorry,you are too young to vote.\")\n",
    "    print(\"Please register to vote as soon as you turn 18!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Your addmission cost is $5.\n"
     ]
    }
   ],
   "source": [
    "# if-elif-else结构\n",
    "\n",
    "age = 12\n",
    "if age<4:\n",
    "    print(\"Your admission cost is $0.\")\n",
    "elif age<18:\n",
    "    print(\"Your addmission cost is $5.\")\n",
    "# 18 以上\n",
    "else:\n",
    "    print(\"You addmission cost is $10.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
